package client

import (
	"context"
	pb "go-programming-tour-book/grpc-demo/proto"
	"google.golang.org/grpc"
	"log"
)

func main() {
	ctx := context.Background()

	clientConn, _ := GetClientConn(ctx, "localhost:8004", []grpc.DialOption{grpc.WithBlock()})

	defer clientConn.Close()

	tagServiceClient := pb.NewTagServiceClient(clientConn)

	resp, _ := tagServiceClient.GetTagList(ctx, &pb.GetTagListRequest{Name: "Go"})

	log.Fatalf("resp:%v", resp)
}

func GetClientConn(ctx context.Context, target string, opts []grpc.DialOption) (*grpc.ClientConn, error) {
	opts = append(opts, grpc.WithInsecure())

	return grpc.DialContext(ctx, target, opts...)
}
